# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=beaker
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.9.1
pkgrel=1
pkgdesc="Caching and sessions WSGI middleware for use with web applications and stand-alone Python scripts and applications (mingw-w64)"
arch=('any')
license=('custom')
url="http://beaker.groovie.org/"
depends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools" "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/bbangert/beaker/archive/${pkgver}.tar.gz)
sha256sums=('b8df930d15bb55e6f47411f1e872d41d81c8a9bf93a41e4c6a4739e084a97e4f')

prepare() {
  cd "${srcdir}/Beaker-${pkgver}"
  #patch -p1 -i ${srcdir}/mingw-python-fix.patch

  cd "${srcdir}"
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}

build() {
 cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    sed -i "s#/usr/bin/python#/usr/bin/env python3#" beaker/crypto/pbkdf2.py
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done 
}

package_python3-beaker() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-beaker/LICENSE"
}

package_python2-beaker() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-beaker/LICENSE"
}

package_mingw-w64-i686-python2-beaker() {
  package_python2-beaker
}

package_mingw-w64-i686-python3-beaker() {
  package_python3-beaker
}

package_mingw-w64-x86_64-python2-beaker() {
  package_python2-beaker
}

package_mingw-w64-x86_64-python3-beaker() {
  package_python3-beaker
}
